﻿

using IotContract.Dtos.Servers.Pushs;
using IotContract.Models.Process;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IotContract.Dtos.Servers.Process;
public class ScUnitDto 
{
    /// <summary>
    /// 设备编号
    /// </summary>
    public int EquipNum { get; set; }
    public long EquipId { get; set; }
    /// <summary>
    /// 点位数据
    /// </summary>
    public List<PushEquipTag> Tags { get; set; }

    /// <summary>
    /// 当前行走位置 （列数）
    /// </summary>  
    public int SC_Bay { get; set; }
    /// <summary>
    /// 当前升降位置  (层数)
    /// </summary>
    public int SC_Level { get; set; }

    /// <summary>
    /// SC 设备状态  0 手动、1 本地自动 、2 联机 
    /// </summary> 
    public int SC_Mode { get; set; }
    /// <summary>
    /// 读取时间
    /// </summary>
    public DateTime? ReadTime { get; set; }
    /// <summary>
    /// 连接状态
    /// </summary>
    public bool Connection { get; set; }

    /// <summary>
    /// 货叉位置
    /// </summary>
    public int SC_Fork1Pos { get; set; }
    /// <summary>
    /// 货叉位置
    /// </summary>
    public int SC_Fork2Pos { get; set; }

    /// <summary>
    /// 0:货叉1作业中；1:货叉1作业完成（报警任务暂停）  
    /// </summary>
    public int JobEndFork1 { get; set; }
    /// <summary>
    /// 0:货叉2作业中；1:货叉2作业完成（报警任务暂停）  
    /// </summary>
    public int JobEndFork2 { get; set; }
    /// <summary>
    /// 任务号
    /// </summary>
    public int JobNumber { get; set; }
    /// <summary>
    /// 写入的任务号
    /// </summary>
    public int W_JobNumber { get; set; }
    /// <summary>
    /// 任务类型
    /// </summary>
    public int JobType { get; set; }

    /// <summary>
    /// 动作类型 1入库 2 出库 3 移库
    /// </summary>
    public int ActionType { get; set; }
    /// <summary>
    /// 0:联机运行停止状态   1:联机运行启动状态,
    /// </summary>
    public int Active { get; set; }

    /// <summary>
    /// 入库站台允许堆垛机取货
    /// </summary>
    public bool IsStoreHSReady
    {
        get; set;
    }
    /// <summary>
    /// 出库站台允许堆垛机放货
    /// </summary>
    public bool IsRetrivalHSReady
    {
        get; set;
    }
    /// <summary>
    /// 报警代码
    /// </summary>
    public int ErrorCode
    {
        get; set;
    }
    /// <summary>
    /// 是否存在托盘1
    /// </summary>
    public bool IsExistTray1 { get; set; }
    /// <summary>
    /// 是否存在托盘2
    /// </summary>
    public bool IsExistTray2 { get; set; }
    /// <summary>
    /// 0:未联机；1: 等待中（联机无任务）;  2:动作中(联机有任务）；
    /// </summary>
    public int SC_State
    {
        get; set;
    }
    /// <summary>
    /// 取货排
    /// </summary>
    public int FromBank
    {
        get; set;
    }
    /// <summary>
    /// 取货排
    /// </summary>
    public int FromBankFork2
    {
        get; set;
    }
    /// <summary>
    /// 取货列
    /// </summary>
    public int FromBay
    {
        get; set;
    }
    /// <summary>
    /// 取货列
    /// </summary>
    public int FromBayFork2
    {
        get; set;
    }
    /// <summary>
    /// 取货层
    /// </summary>
    public int FromLevel
    {
        get; set;
    }
    /// <summary>
    /// 取货层
    /// </summary>
    public int FromLevelFork2
    {
        get; set;
    }
    /// <summary>
    /// 出入库站台
    /// </summary>
    public int FromStation
    {
        get; set;
    }
    /// <summary>
    /// 放货站台
    /// </summary>
    public int FromStationFork2
    {
        get; set;
    }
    /// <summary>
    /// 放货排
    /// </summary>
    public int ToBank
    {
        get; set;
    }
    /// <summary>
    /// 放货排
    /// </summary>
    public int ToBankFork2
    {
        get; set;
    }
    /// <summary>
    /// 放货列
    /// </summary>
    public int ToBay
    {
        get; set;
    }
    /// <summary>
    /// 放货层
    /// </summary>
    public int ToLevel { get; set; }
    /// <summary>
    /// 放货列
    /// </summary>
    public int ToBayFork2
    {
        get; set;
    }
    /// <summary>
    /// 放货层
    /// </summary>
    public int ToLevelFork2
    {
        get; set;
    }
    /// <summary>
    /// 放货站台
    /// </summary>
    public int ToStation
    {
        get; set;
    }

    /// <summary>
    /// 任务号2
    /// </summary>
    public int JobNumberFork2
    {
        get; set;
    }
    /// <summary>
    /// 放货站台
    /// </summary>
    public int ToStationFork2
    {
        get; set;
    }
    /// <summary>
    /// 任务ID
    /// </summary>
    public string JobID { get; set; }
    /// <summary>
    /// 前任务ID
    /// </summary>
    public string JobIDOld { get; set; }


    /// <summary>
    /// 根据属性获取点位
    /// </summary>
    /// <param name="Property"></param>
    /// <returns></returns>
    public PushEquipTag GetTagByProperty(string Property)
    {
        var tag = Tags.FirstOrDefault(x => x.TagProperty == Property);
        if (tag == null)
        {
            return null;
        }
        else
        {
            return (PushEquipTag)tag.Clone();
        }
    }

    /// <summary>
    /// 是否是实时数据
    /// </summary>
    public bool IsRealTime()
    {
        if (ReadTime == null)
        {
            return false;
        }
        return DateTime.Now.Subtract(ReadTime.Value).TotalSeconds < 60;

    }
}
